from jk_test.sendrequest import SendRequest  # 导包


class SmsHome:
    def __init__(self):
        self.url = "http://localhost:8080"

    # 添加一个新的广告
    def create_gg(self, body, headers):
        url = self.url + "/home/brand/create"
        method = "post"
        return SendRequest.send_request(url, method, json=body, headers=headers)

    # 删除广告
    def delete_gg(self, body, headers):
        url = self.url + "/home/brand/delete"
        method = "post"
        return SendRequest.send_request(url, method, data=body, headers=headers)

    # 广告分页
    def list_gg(self, body, headers):
        url = self.url + "/home/brand/list"
        method = "get"
        return SendRequest.send_request(url, method, data=body, headers=headers)

    # 编辑广告内容
    def update_gg(self, body, headers):
        url = self.url + "/home/brand/update/recommendStatus"
        method = "post"
        return SendRequest.send_request(url, method, data=body, headers=headers)

    # 修改广告排序id
    def sort_gg(self, body, headers):
        method = "post"
        return SendRequest.send_request(url, method, data=body, headers=headers)


if __name__ == '__main__':
    # 登录用户，获取令牌token
    url = "http://localhost:8080/admin/login"
    method = "post"
    body1 = {
        "username": "admin",
        "password": "macro123"
    }
    res = SendRequest.send_request(url, method, json=body1)
    token = res.get("body").get("data").get("tokenHead") + res.get("body").get("data").get("token")

    test1 = SmsHome()
    body2 = [
        {
            "brandId": 11,
            "brandName": "库洛卡牌",
            "id": 11,
            "recommendStatus": 11,
            "sort": 11
        }
    ]
    print(test1.create_gg(body2, {"Authorization": token}))

    test2 = SmsHome()
    body3 = {
        "ids": 48
    }  # ids的编号可以修改，只要在数据库可以找到对应的ID编号
    print(test2.delete_gg(body3, {"Authorization": token}))

    test3 = SmsHome()
    body4 = {
        "brandName": "",
        "pageNum": "",
        "pageSize": "",
        "recommendStatus": ""
    }
    print(test3.list_gg(body4, {"Authorization": token}))

    test4 = SmsHome()
    body5 = {
        "ids": 6,
        "recommendStatus": 11
    }  # 数据可以修改
    print(test4.update_gg(body5, {"Authorization": token}))

    test5 = SmsHome()
    url = "http://localhost:8080/home/brand/update/sort/47"  # 可以修改url最后的数字id选择要修改的广告
    body6 = {
        "sort": 109
    }
    print(test5.sort_gg(body6, {"Authorization": token}))
